import { useLocation } from "react-router-dom";
import { QUESTION_EDIT_PATHNAME, QUESTION_STAT_PATHNAME } from "../router";

type PageType = "edit" | "stat" | "other";

function useQuestionPageType(): {
  isEditPage: boolean;
  isStatPage: boolean;
  pageType: PageType;
} {
  const { pathname } = useLocation();

  const isEditPage = pathname.startsWith(QUESTION_EDIT_PATHNAME);
  const isStatPage = pathname.startsWith(QUESTION_STAT_PATHNAME);
  const pageType: PageType = isEditPage
    ? "edit"
    : isStatPage
    ? "stat"
    : "other";

  return {
    isEditPage,
    isStatPage,
    pageType,
  };
}

export default useQuestionPageType;
